<template>
    <view class="p-top20 p-bot30" :style="{ '--color': color }">
        <navBar title="服务卡领取" :fromShare="fromShare"></navBar>
        <Sharer v-if="fromShare == 1" :pageData="share_member_info"></Sharer>

        <view class="Wrapper">
            <view class="imgBox">
                <image :src="$imgUrls(pageData.background)" mode="aspectFill" class="CardImg"></image>
                <view class="imgBox_content">
                    <view class="CredTop">
                        <image :src="$imgUrls(pageData.logo)" mode="aspectFill" class="Logo"></image>
                        <view class="d-flex flex-1 f-column j-sa">
                            <text class="ellipsis white size32 bold">{{ pageData.name }}</text>
                            <text class="Time white size28">{{ pageData.expire_time }}</text>
                        </view>
                    </view>
                    <view class="numBox" v-if="pageData.last_times">
                        <text class="Tips">剩余</text>
                        <text class="Tips_num">{{ pageData.last_times }}</text>
                        <text class="Tips">次</text>
                    </view>
                </view>
            </view>

            <view class="intro">
                <image :src="$imgUrls(pageData.logo)" mode="aspectFill" class="Logo"></image>
                <view class="intro_box">
                    <text class="ellipsis black size32 bold">{{ pageData.name }}</text>
                    <text class="ellipsis color_99 h6 m-top8">{{ pageData.desc }}</text>
                    <text class="ellipsis color_cc h6 m-top8">{{ pageData.expire_time }}</text>
                </view>
                <view class="actuality" v-if="pageData.give_info && !pageData.give_info.give_time">
                    <view class="d-flex a-center">
                        <view class="Use" @click="getGiftCard">领取</view>
                    </view>
                </view>
            </view>
        </view>
        <CollRecord :pageData="pageData.give_info"></CollRecord>
        <Richtext :pageData="pageData.content"></Richtext>
        <Store :pageData="store_list" v-if="store_list.length"></Store>
        <showModel @cancelFunc="showModal = false" goHome="0" v-if="showModal" type="2"></showModel>
    </view>
</template>

<!-- type  1商品 2优惠券 3余额 4积分', -->
<script>
    import { mapState } from 'vuex';
    import Sharer from '@/subCard/components/Sharer.vue';
    import ServerItem from '@/subCard/components/ServerItem.vue';
    import useNow from '@/subCard/components/useNow.vue';
    import getNow from '@/subCard/components/getNow.vue';
    import Richtext from '@/subCard/components/Richtext.vue';
    import Store from '@/subCard/components/Store.vue';
    import Records from '@/subCard/components/Records.vue';
    import CollRecord from '@/subCard/components/CollRecord.vue';
    export default {
        components: {
            Sharer,
            ServerItem,
            Records,
            useNow,
            getNow,
            Richtext,
            Store,
            CollRecord
        },
        data() {
            return {
                fromShare: 0,
                headImg: 'https://imgcdn.mogoie.com/6099/1709797684310.JPG',
                id: '',
                goods: '',
                item_use: '',
                times_card_info: '',
                store_list: [],
                qr: '',
                shop_id: '',
                share_member_info: '',
                Show: false,
                pay_log_id: '',
                pageData: '',
                showModal: false
            };
        },
        onLoad(opt) {
            if (opt.id) this.id = opt.id;
            if (opt.fromShare) this.fromShare = opt.fromShare;
            if (opt.pay_log_id) this.pay_log_id = opt.pay_log_id;
            if (opt.shop_id) this.shop_id = opt.shop_id;
        },
        onShow() {
            if (this.item_use) this.$refs.useNow.getDeliveryInfo();
            this.getTimeItemDetail();
        },
        methods: {
            getTimeItemDetail() {
                this.$http
                    .get({
                        url: '/TimeCardApi/newTimesCardDetail',
                        data: {
                            id: this.id,
                            pay_log_id: this.pay_log_id
                        }
                    })
                    .then((res) => {
                        if (res.code != 200) return this.$Toast(res.msg);
                        const result = res.data;
                        this.pageData = result;
                        this.qr = result.qr;
                        this.goods = result.goods;
                        this.item_use = result.item_use_log_find;
                        this.times_card_info = result.times_card_info;
                        this.store_list = result.store_list || [];
                        if (result.share_member_info) this.share_member_info = result.share_member_info;
                    });
            },
            getGiftCard() {
                if (!this.vid) return (this.showModal = true);
                this.$showLoading('');
                this.$http
                    .post({
                        url: '/TimeCardApi/getGiftCard',
                        data: {
                            pay_log_id: this.pay_log_id
                        }
                    })
                    .then((res) => {
                        this.$hideLoading();
                        if (res.code != 200) return this.$Toast(res.msg);
                        this.$Toast(res.msg);
                        this.getTimeItemDetail();
                    });
            }
        },
        computed: {
            ...mapState(['color', 'vid', 'share_v_id'])
        },
        onShareAppMessage(res) {
            return {
                title: `${this.goods.name}`,
                path: `/pages/index/index?id=${this.id}&pageType=32&share_v_id=${this.vid}`, // 动态设置跳转路径
                imageUrl: `${this.goods.img}` // 分享图片链接
            };
        }
    };
</script>
<style>
    page {
        background-color: #f2f2f2;
    }
</style>
<style lang="scss" scoped>
    .Wrapper {
        width: 690rpx;

        background-color: #fff;

        margin: 0 auto 30rpx;
        border-radius: 10rpx;
        overflow: hidden;

        .imgBox {
            width: 100%;
            height: 350rpx;
            position: relative;
            overflow: hidden;

            .CardImg {
                width: 100%;
                height: 100%;
            }

            .imgBox_content {
                position: absolute;
                inset: 0;
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                align-items: flex-start;
                padding: 20rpx;

                .CredTop {
                    width: 100%;
                    display: flex;
                }

                .numBox {
                    padding: 2rpx 14rpx;
                    background-color: rgba(0, 0, 0, 0.5);
                    color: #ffffff;
                    border-radius: 10rpx;

                    .Tips {
                        font-size: 24rpx;
                    }

                    .Tips_num {
                        font-size: 30rpx;
                        margin: 0 4rpx;
                    }
                }
            }
        }

        .intro {
            width: 100%;
            background-color: #ffffff;

            display: flex;
            align-items: center;
            border-top: 1px solid #f2f2f2;
            overflow: hidden;
            padding: 24rpx;

            &_box {
                flex: 1;
                display: flex;
                flex-direction: column;
            }

            .actuality {
                display: flex;
                flex-direction: column;
                align-items: center;

                .Use {
                    width: 160rpx;
                    height: 60rpx;
                    border-radius: 10rpx;
                    background-color: var(--color);
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    color: #ffffff;
                    font-size: 26rpx;
                    position: relative;
                }

                .shareBtn {
                    width: 100%;
                    height: 100%;
                    position: absolute;
                    top: 0;
                    left: 0;
                    z-index: 10;
                    background-color: transparent;
                    border: none;
                }

                .lineBox {
                    width: 170rpx;
                    margin-top: 10rpx;
                }

                .residue {
                    margin-top: 10rpx;
                    color: #999;
                }
            }
        }

        .Logo {
            width: 100rpx;
            height: 100rpx;
            border-radius: 50%;
            margin-right: 20rpx;
        }
    }
    .Pop {
        width: 100%;
        height: 100vh;
        position: fixed;
        inset: 0;
        z-index: 100;
        background-color: rgba(0, 0, 0, 0.2);
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
    }
</style>
